package br.com.jogo.neg;

import com.badlogic.gdx.graphics.Color;
import com.badlogic.gdx.graphics.g2d.SpriteBatch;

import br.com.jogo.assets.Assets;
import br.com.jogo.interfaces.Drawable;

public class BattleGrid implements Drawable {

	public Tile[][] tiles;

	public BattleGrid() {
		tiles = new Tile[12][3];

		for (int i = 0; i < tiles.length; i++) {
			for (int j = 0; j < tiles[i].length; j++) {
				tiles[i][j] = new Tile(i, j);
			}
		}
	}

	@Override
	public void Draw(SpriteBatch sb, float deltaTime) {

		sb.disableBlending();
		sb.draw(Assets.atlas.findRegion("background"), 0, 0);
		sb.enableBlending();

		for (int i = 0; i < Assets.grid.length; i++) {
			for (int j = 0; j < Assets.grid[i].length; j++) {
				
				if(tiles[j][i].element != null) {
					sb.setColor(Color.BLUE);
				} 
				
				sb.draw(Assets.grid[i][j], j * Tile.TILE_WIDTH, i
						* Tile.TILE_HEIGHT);
				
				sb.setColor(Color.WHITE);
			}
		}
	}

	public void clearTiles() {
		for (int i = 0; i < tiles.length; i++) {
			for (int j = 0; j < tiles[i].length; j++) {
				tiles[i][j].element = null;
			}
		}
	}

	public void addElement(GameObject object) {

		for (int i = 0; i < tiles.length; i++) {
			for (int j = 0; j < tiles[i].length; j++) {

				if (tiles[i][j].bounds.overlaps(object.bounds)) {
					tiles[i][j].element = object;
				}
			}
		}

	}

	

}
